﻿using System.Windows.Controls;
using Microsoft.Extensions.DependencyInjection;
using RotovapPlatform.UI.ViewModels.RecipeManagement;

namespace RotovapPlatform.UI.Views.RecipeManagement
{
	public partial class RecipeEditorView : UserControl
	{
		public RecipeEditorView(RecipeEditorViewModel viewModel)
		{
			InitializeComponent();
			DataContext = viewModel;
		}

		public string ExperimentGroupName
		{
			get
			{
				if (DataContext is RecipeEditorViewModel viewModel)
				{
					return viewModel.DisplayGroupName;
				}
				return string.Empty;
			}
		}

		private async void MaterialNameComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			if (DataContext is RecipeEditorViewModel viewModel)
			{
				await viewModel.OnMaterialNameChangedAsync();
			}
		}

		private void CondensationCleaningSolutionComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			if (DataContext is RecipeEditorViewModel viewModel)
			{
				viewModel.OnCondensationCleaningSolutionChanged();
			}
		}

		private void RotaryBottleCleaningSolutionComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			if (DataContext is RecipeEditorViewModel viewModel)
			{
				viewModel.OnRotaryBottleCleaningSolutionChanged();
			}
		}

		private async void RefreshButton_Click(object sender, System.Windows.RoutedEventArgs e)
		{
			if (DataContext is RecipeEditorViewModel viewModel)
			{
				await viewModel.RefreshMaterialsAndSolutionsAsync();
			}
		}
	}
}

